# coding:utf-8
from PyQt6.QtCore import Qt, pyqtSignal
from PyQt6.QtWidgets import QApplication
from qfluentwidgets import FluentIcon as FIF, SplitFluentWindow, NavigationTreeWidget, NavigationPushButton

from common import SingleIcon, FakerUtils, Icon
from .add_order_interface import AddOrderDialog
from .faker_signal import fakerSignals
from .list_order_interface import ListOrderInterface
from .batch_interface import BatchInterface


class BatchWindow(SplitFluentWindow):
    closed = pyqtSignal()
    def __init__(self, parent=None):
        super().__init__(parent)
        self.listOrderInterface = ListOrderInterface(self)
        self.batchInterface = BatchInterface(self)

        self.__initWidgets()
        self.__initNavigation()

    def __initWidgets(self):
        self.setMinimumSize(800, 600)
        self.resize(1240, 800)
        self.setWindowIcon(SingleIcon.FALSE.icon())
        self.setWindowTitle('Faker 随机数据生成器')
        self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        self.navigationInterface.setExpandWidth(230)
        self.navigationInterface.setAcrylicEnabled(True)
        self.navigationInterface.setMenuButtonVisible(False)
        self.navigationInterface.setReturnButtonVisible(True)
        self.navigationInterface.setCollapsible(False)

        geometry = QApplication.primaryScreen().geometry()
        self.move(geometry.width() // 2 - self.width() // 2, geometry.height() // 2 - self.height() // 2)

    def __initNavigation(self):
        self.navigationInterface.addWidget(
            routeKey='avatar',
            widget=NavigationPushButton(FIF.ADD_TO, '添加指令', False),
            onClick=self.showMessageBox,
        )
        self.addSubInterface(self.listOrderInterface, Icon.MENU, '列表')
        self.addSubInterface(self.batchInterface, Icon.BATCH, '批量生成')

    def showMessageBox(self):
        dialog = AddOrderDialog(self)
        if dialog.exec():
            data = dialog.get_data()
            FakerUtils().add_provider(data)
            fakerSignals.addProvider.emit(data)

    def closeEvent(self, a0):
        self.closed.emit()

if __name__ == '__main__':
    app = QApplication([])
    window = BatchWindow()
    window.show()
    app.exec()
